﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Young3.FMSearch.Core.Attributes;
using Young3.FMSearch.Core.Managers;

namespace Young3.FMSearch.Core.Entities.GameVersions
{
    internal class Steam_11_1_1: IIVersion
    {
        public Steam_11_1_1()
        {
            MemoryAddresses = new VersionMemoryAddresses();
            PersonEnum = new VersionPersonEnumPointers();
            PersonOffsets = new PersonVersionOffsets();
        }

        public string Description
        {
            get { return "11.1.1 Steam"; }
        }

        public bool SupportsProcess(FMProcess process)
        {
            if (process.VersionDescription != "11.1.1f158038") return false;

            var dt = ProcessManager.ReadDateTime(MemoryAddresses.CurrentDateTime);
            if (dt.Year < 2009 || dt.Year >= 2100)
                return false;

            return true;
        }

        public IVersionMemoryAddresses MemoryAddresses { get; private set; }
        public IVersionPersonEnumPointers PersonEnum { get; private set; }
        public IPersonVersionOffsets PersonOffsets { get; private set; }

        public class VersionMemoryAddresses : IVersionMemoryAddresses
        {
            [MemoryAddress(CountLength = 4, BytesToSkip = 0x28)]
            public int City { get { return 0x256d3bc; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int Club { get { return 0x256d3c0; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int Continent { get { return 0x256d3c8; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int Country { get { return 0x256d3e0; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int League { get { return 0x256d3c4; } }

            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int Language { get { return 0x256d3d8; } }

            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28)]
            public int Stadium { get { return 0x256d40c; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28, ObjectOffset = 0)]
            public int Team { get { return 0x256d418; } }
            [MemoryAddressAttribute(CountLength = 4, BytesToSkip = 0x28, ObjectOffset = 0)]
            public int Person { get { return 0x256d3e8; } }

            public int CurrentDateTime { get { return 0x256d570; } }

            [MemoryAddress(CountLength = 4, BytesToSkip = 0x48)]
            public int ActiveObject { get { return 0x22faadc; } }
        }

        public class VersionPersonEnumPointers : IVersionPersonEnumPointers
        {
            public int Player { get { return 0x1f0a44c; } }
            public int Staff { get { return 0x1f095f4; } }
            public int PlayerStaff { get { return 0x1f5e644; } }
            public int HumanManager { get { return 0x1f12814; } }
        }

        /// <summary>
        /// How many bytes the pointer should be corrected for persons.
        /// Complies with 'AddressUsedInGame' in FMRTE
        /// </summary>
        public class PersonVersionOffsets : IPersonVersionOffsets
        {
            public int Player { get { return -300; } }
            public int Staff { get { return -0x44; } }
            public int HumanManager { get { return -0x44; } }
            public int PlayerStaff { get { return -0x15c; } }
        }
    }
}
